package com.bygf.curve.demo;

import com.bygf.curve.Curve;
import com.bygf.curve.XYCurve;
import com.bygf.curve.panel.ChartPanel;
import com.bygf.curve.utils.ToolTipFormat;
import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author sunyupei
 */
public class XYCurveDemo2 extends javax.swing.JPanel {

    ChartPanel chartPanel = new ChartPanel();

    /**
     * Creates new form XYCurve
     */
    public XYCurveDemo2() {
        initComponents();
        chartPanel = new ChartPanel("应力、温度历史曲线", "位置", "应力(µε)", "", false);
        chartPanel.setBounds(0, 0, this.getWidth(), this.getHeight());
        chartPanel.getYAxis().setStartValue(-1);
        chartPanel.getYAxis().setEndValue(1);
        chartPanel.getYAxis().setDecimalFormat(new DecimalFormat("#.##"));
        chartPanel.getXAxis().setStartValue(0);
        chartPanel.getXAxis().setEndValue(360);
        chartPanel.setY2AxisVisible(true);
        chartPanel.getY2Axis().setTitle("温度(℃)");
        chartPanel.getY2Axis().setStartValue(0);
        chartPanel.getY2Axis().setEndValue(100);
        chartPanel.getTitlePanel().setTitleFont(new Font("宋体", Font.BOLD, 26));
        List<Curve> curveList = new ArrayList<>();
        XYCurve sin = new XYCurve("设备1-应力曲线");
        sin.setToolTipFormat(new ToolTipFormat("{0}:sin({1})={2}", null, new DecimalFormat("#.##")));
        XYCurve cos = new XYCurve("设备1-温度曲线");
        cos.setToolTipFormat(new ToolTipFormat("{0}:cos({1})*50+50={2}", null, new DecimalFormat("#.##")));
        cos.setUsedY2Axis(true);
        for (int i = 0; i < 360; i++) {
            sin.addItem(i, Math.sin(Math.toRadians(i)));
            cos.addItem(i, Math.cos(Math.toRadians(i)) * 50 + 50);
        }
        sin.getRender().setShapeVisible(true);
        cos.getRender().setColor(Color.GREEN);
        cos.getRender().setShapeVisible(true);
        curveList.add(cos);
        curveList.add(sin);
        chartPanel.getCurvePanel().setCurveList(curveList);
        chartPanel.getCurvePanel().setBackColor(Color.BLACK);
        this.add(chartPanel);
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        super.setBounds(x, y, width, height);
        chartPanel.setBounds(0, 0, this.getWidth(), this.getHeight());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 547, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 387, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
